//
//  category.m
//  NewApp
//
//  Created by  on 12-7-5.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "NACategory.h"
#import "Constants.h"

@implementation NACategory
@synthesize subCategory,isChild,isExpanded;

- (id) initWithDictionary:(NSDictionary *)dictionary {
    if (self = [super init]) {
        self.isExpanded = NO;
        
        self.sID = ([dictionary objectForKey:kID] == nil) ? @"" : [dictionary objectForKey:@"id"];
        self.title = ([dictionary objectForKey:kTitle] == nil) ? @"" : [dictionary objectForKey:kTitle];
        if ([dictionary objectForKey:kData2]) {
            NSArray *data2 = [dictionary objectForKey:kData2];
            NSMutableArray *subcategorys = [[NSMutableArray alloc] init];
            for (NSDictionary *dict in data2) {
                NACategory *cg = [[NACategory alloc] initWithDictionary:dict];
                [subcategorys addObject:cg];
                [cg release];
            }
            
            self.subCategory = subcategorys;
            [subcategorys release];
            
        } 
        
        if(self.subCategory != nil) {
            for (NACategory *category in self.subCategory) {
                category.isChild = YES;
            }
        }
        
    }
    
    return self;
}

- (void) dealloc {
    [subCategory release];
    [super dealloc];
}

@end
